package concurrence;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by gzhd on 2017/11/20.
 */
public class ReenterLockCondition implements Runnable{
    public static ReentrantLock lock = new ReentrantLock();
    public static Condition condition=lock.newCondition();
    @Override
    public void run() {
        try {
            lock.lock();
            System.out.println("lock is locking``````````");
            condition.await();
            System.out.println("Thread is going on");


        } catch (Exception e) {
        }
        finally {
            lock.unlock();
        }

    }

    public static void main(String[] args) throws Exception{
        ReenterLockCondition tl = new ReenterLockCondition();
        Thread t1 = new Thread(tl);
        t1.start();
        System.out.println("t1.start```````");
        System.out.println("sleep```");
        Thread.sleep(1000);
        System.out.println("wake up``");
        lock.lock();
        condition.signal();
        System.out.println("signal```");
        lock.unlock();

    }
}
